class Solution {
public:
    int minNumberOfFrogs(string croakOfFrogs) {
        unordered_map<char, int> m;
        for (int i = 0; i < croakOfFrogs.size(); i++)
        {
            if (croakOfFrogs[i] == 'c')
            {
                if (m['k'] == 0)
                {
                    m['c']++;
                }
                else
                {
                    m['k']--;
                    m['c']++;
                }
            }
            if (croakOfFrogs[i] == 'r')
            {
                if (m['c'] == 0)
                {
                    return -1;
                }
                else
                {
                    m['c']--;
                    m['r']++;
                }
            }
            if (croakOfFrogs[i] == 'o')
            {
                if (m['r'] == 0)
                {
                    return -1;
                }
                else
                {
                    m['r']--;
                    m['o']++;
                }
            }

            if (croakOfFrogs[i] == 'a')
            {
                if (m['o'] == 0)
                {
                    return -1;
                }
                else
                {
                    m['o']--;
                    m['a']++;
                }
            }

            if (croakOfFrogs[i] == 'k')
            {
                if (m['a'] == 0)
                {
                    return -1;
                }
                else
                {
                    m['a']--;
                    m['k']++;
                }
            }

        }
        if (m['k'] == 0)
            return -1;
        else if (m['c'] != 0)
        {
            return -1;
        }
        else
            return m['k'];
    }
};